package cn.kys.modules.system.controller;

import cn.kys.common.result.Result;
import cn.kys.common.utils.SecurityUtils;
import cn.kys.modules.security.security.vo.JwtUser;
import cn.kys.modules.system.domain.Dept;
import cn.kys.modules.system.domain.User;
import cn.kys.modules.system.service.LayerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/layer_api")
public class LayerApi {
    @Autowired
    private LayerService layerService;


    /**
     * @Author zhaoxw
     * @Description  封装该层对象
     * @Date 13:53 2024/3/25
     * @return
     **/
    @GetMapping("/addLayer")
    public Result addLayer(@RequestParam("name") String name, @RequestParam("cname") String cname, @RequestParam("url") String url, @RequestParam("type") String type) throws Exception {
       try {
           layerService.addLayer(name,cname,url,type);
           return Result.success();
       }catch (Exception e){
           return Result.error("名称已经存在");
       }

    }



    @GetMapping("/editLayer")
    public Map editLayer(@RequestParam("id") String id,@RequestParam("name") String name,@RequestParam("cname") String cname,@RequestParam("url") String url,@RequestParam("type") String type){
        Map returnMap = new HashMap();
        try {
            layerService.editLayer(id,name,cname,url,type);
            returnMap.put("success",true);
            returnMap.put("resMsg","获取成功");
        } catch (Exception e) {
            e.printStackTrace();
            returnMap.put("success",false);
            returnMap.put("resMsg","异常");
        }
        return returnMap;
    }



    @GetMapping("/getAllLayers")
    public Map getAllLayers(){
        Map returnMap = new HashMap();
        try {
            List list = layerService.getAllLayers();
            returnMap.put("data",list);
            returnMap.put("success",true);
            returnMap.put("resMsg","获取成功");
        } catch (Exception e) {
            e.printStackTrace();
            returnMap.put("success",false);
            returnMap.put("resMsg","异常");
        }
        return returnMap;
    }

    @GetMapping("/getAllTypeLayers")
    public Map getAllTypeLayers(){
        Map returnMap = new HashMap();
        try {
            Map map = layerService.getAllTypeLayers();
            returnMap.put("data",map);
            returnMap.put("success",true);
            returnMap.put("resMsg","获取成功");
        } catch (Exception e) {
            e.printStackTrace();
            returnMap.put("success",false);
            returnMap.put("resMsg","异常");
        }
        return returnMap;
    }

    /**
     *@Desxription:
     *@Date:13:39 2022/3/11
     */
    @GetMapping("/delLayerById")
    public Map delLayerById(@RequestParam("id") String id){
        Map returnMap = new HashMap();
        try {
            Map map = layerService.delLayerById(id);
            returnMap.put("data",map);
            returnMap.put("success",true);
            returnMap.put("resMsg","获取成功");
        } catch (Exception e) {
            e.printStackTrace();
            returnMap.put("success",false);
            returnMap.put("resMsg","异常");
        }
        return returnMap;
    }
}

